<?php
/** @var CatalogController $this */
/** @var Catalog $model */
$this->breadcrumbs = array(
    'Catalogs' => array('index'),
    Yii::t('AweCrud.app', 'Manage'),
);

$this->menu = array(
    array('label' => Yii::t('AweCrud.app', 'List') . ' ' . Catalog::label(2), 'icon' => 'list', 'url' => array('index')),
    array('label' => Yii::t('AweCrud.app', 'Create') . ' ' . Catalog::label(), 'icon' => 'plus', 'url' => array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
	$('#catalog-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	$('#bulkAction').html('');
    var moveToTrashOpt = '<option value=\"moveToTrash\">Move To Trash</option>';
    $('#bulkAction').append(moveToTrashOpt);
	return false;
});

$('.bulk-action form').submit(function(){
	$('#catalog-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});

$('.trash-form form').submit(function(){
	$('#catalog-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	$('#bulkAction').html('');
    var restoreOpt = '<option value=\"restore\">Restore</option>';
    var deleteOpt = '<option value=\"delete\">Delete</option>';
    $('#bulkAction').append(restoreOpt);
    $('#bulkAction').append(deleteOpt);
	return false;
});
");
?>

<fieldset>
    <legend>
        <?php echo Yii::t('AweCrud.app', 'Manage') ?> <?php echo Catalog::label(2) ?>    </legend>
    <div class="search-form">
        <?php $this->renderPartial('_search', array(
            'model' => $model,
        ));?>
    </div>
    <!--End search parent-->
    <div class="trash-form">
        <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'searchTrash',
            'type' => 'search',
            'action' => Yii::app()->createUrl($this->route),
            'method' => 'get',
        ));
        echo $form->hiddenField($model, 'is_active', array('value' => 0));
        $trashNum = Catalog::Model()->count("is_active=:is_active", array("is_active" => 0));
        $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'label' => 'Trash (' . $trashNum . ')', 'type' => 'primary',));
        $this->endWidget();
        ?>
    </div>
    <div class="bulk-action">
        <?php
        $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'moveToTrash',
            'action' => Yii::app()->createUrl("catalog/bulk"),
            'method' => 'get',
        ));
        $this->widget('bootstrap.widgets.TbExtendedGridView', array(
            'id' => 'catalog-grid',
            'type' => 'striped condensed bordered',
            'itemsCssClass' => 'table table-striped',
            'dataProvider' => $model->search(),
            'filter' => $model,
            'selectableRows' => 10,
            'columns' => array(
                array(
                    'id' => 'selectedIds',
                    'class' => 'CCheckBoxColumn'
                ),
                array(
                    'class' => 'ext.widgets.TbActionDataColumn',
                    'name' => 'catalog_name',
                    'url' => $this->createUrl('catalog/relational'),
                    'afterAjaxUpdate' => 'js:function(tr,rowid,data){
                }',
                ),
                'catalog_name',
                'sort_id',
                'parent',
            ),
        ));
        echo CHtml::dropDownList('bulkAction', '', array("moveToTrash" => "Move to trash"));
        $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'label' => 'Action', 'type' => 'primary',));
        $this->endWidget();
        ?>
    </div>
</fieldset>